package com.cadre.web.controller.officer;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.cadre.common.utils.R;
import com.cadre.common.utils.annotation.SysLog;
import com.cadre.common.utils.common.GenerateUUID;
import com.cadre.common.utils.oldutil.DateUtil;
import com.cadre.common.utils.oldutil.ValidatorUtils;
import com.cadre.system.domain.officer.A01;
import com.cadre.system.domain.officer.A10;
import com.cadre.system.service.A01Service;
import com.cadre.system.service.A10Service;
import com.cadre.system.service.DIC_ZBService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(value = "专业Controller", tags = {"干部专业接口"})
@RequestMapping({"/profess/a10"})
@RestController
/* loaded from: A10Controller.class */
public class A10Controller {
    @Autowired
    private A10Service a10Service;
    @Autowired
    private A01Service a01Service;
    @Resource
    private DIC_ZBService dIC_ZBService;

    @GetMapping({"/list/{personId}"})
    @ApiOperation("获取专业列表")
    public R list(@PathVariable String personId) {
        return R.ok().put("page", (Object) this.a10Service.selectList(personId));
    }

    @GetMapping({"/info/{flowId}"})
    @ApiOperation("获取专业信息")
    public R info(@PathVariable("flowId") String flowId) {
        return R.ok().put("a10", (Object) ((A10) this.a10Service.getBaseMapper().selectById(flowId)));
    }

    @PostMapping({"/save"})
    @SysLog(value = "添加专业信息", target = "A01", set = "A10", type = 0)
    @ApiOperation("添加专业")
    public R save(@RequestBody A10 a10) {
        a10.setFlowid(GenerateUUID.getUUID());
        this.a10Service.getBaseMapper().insert(a10);
        return R.ok();
    }

    @PostMapping({"/update"})
    @SysLog(value = "修改专业信息", target = "A01", set = "A10", type = 1)
    @ApiOperation("更新专业")
    public R update(@RequestBody A10 a10) {
        ValidatorUtils.validateEntity(a10, new Class[0]);
        this.a10Service.updateById(a10);
        return R.ok();
    }

    @PostMapping({"/delete"})
    @SysLog(value = "删除专业信息", target = "A01", set = "A10", type = DateUtil.SUB_MONTH)
    @ApiOperation("专业删除")
    public R delete(@RequestBody String[] flowids) {
        this.a10Service.getBaseMapper().deleteBatchIds(Arrays.asList(flowids));
        return R.ok();
    }

    @GetMapping({"/getA1020"})
    @ApiOperation("职业资格名称字典")
    public R getA1020() {
        Map<String, Object> map = new HashMap<>();
        map.put("tableName", "DIC_GB8561");
        return R.ok().put("data", (Object) this.dIC_ZBService.getAllForTree(map));
    }

    @PostMapping({"/saveA0186/{personid}"})
    @ApiOperation("更新A0186信息(批量解析)")
    public R saveA0195(@RequestBody A10[] a10, @PathVariable String personid) {
        List<A10> listA10 = this.a10Service.getBaseMapper().selectList(new LambdaQueryWrapper<A10>().eq(A10::getPersonid, personid));
        for (int n = 0; n < listA10.size(); n++) {
            listA10.get(n).setIsout((short) 0);
            this.a10Service.updateById(listA10.get(n));
        }
        if (a10.length <= 0) {
            A01 a01 = (A01) this.a01Service.getBaseMapper().selectById(personid);
            a01.setA0186("");
            this.a01Service.updateById(a01);
            return R.ok();
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < a10.length; i++) {
            A10 a = (A10) this.a10Service.getBaseMapper().selectById(a10[i].getFlowid());
            a.setIsout((short) 1);
            this.a10Service.updateById(a);
            if (i == 0) {
                sb.append(a.getA1005());
            } else {
                sb.append(",").append(a.getA1005());
            }
        }
        A01 a012 = (A01) this.a01Service.getBaseMapper().selectById(personid);
        a012.setA0186(sb.toString());
        this.a01Service.updateById(a012);
        return R.ok();
    }

    @RequestMapping(value = {"/getAllForTreeByName"}, method = {RequestMethod.GET})
    @ApiOperation("读取模糊字典")
    public R getAllForTreeByName(@RequestParam String tableName, @RequestParam String name) {
        Map<String, Object> map = new HashMap<>();
        map.put("tableName", tableName);
        map.put("name", name);
        return R.ok().put("data", (Object) this.dIC_ZBService.getAllForTree(map));
    }
}
